import axios from 'axios';

const API_URL = 'http://82.157.18.165/v1';
const API_KEY = 'app-hY1AfVz8IRvGzfbxOuQFqIq3';

// 创建axios实例
const apiClient = axios.create({
  baseURL: API_URL,
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  }
});

// 发送聊天消息
export const sendChatMessage = async (query, conversationId = '', inputs = {}, user = 'user', files = [], parentMessageId = '') => {
  try {
    const response = await fetch(`${API_URL}/chat-messages`, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${API_KEY}`,
        'Content-Type': 'application/json',
        'Accept': '*/*'
      },
      body: JSON.stringify({
        query,
        conversation_id: conversationId,
        inputs,
        user,
        response_mode: 'streaming',
        files,
        parent_message_id: parentMessageId
      })
    });

    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
    }

    return response;
  } catch (error) {
    console.error('发送聊天消息失败:', error);
    throw error;
  }
};

export default {
  sendChatMessage
}; 